<!--
 * @Date: 2022-09-07 11:35:04
 * @LastEditors: eric shijie.zhu@jgdt.com
 * @LastEditTime: 2023-02-16 16:15:23
 * @Description:  平台主数据维护 - 表格使用状态按钮
-->
<template>
  <div class="status-button" @click="handleChange">
    <el-switch v-if="value!==null" v-model="value" :active-value="1" :inactive-value="0"></el-switch>
    <span v-else></span>
  </div>
  </template>
  
  <script>
  import _ from 'lodash-es'
  import mitt from 'mitt'

// 触发事件
// emitter.emit('event_name', payload)
  export default {
    name: 'CustomSwitch',
    data() {
      return {
        value: false,
        emitter: null,
        rendered: false,
      };
    },
    created() {
      this.value = this.params.value;
      console.log('value', this.value);
      this.emitter  = mitt() 
    },
    mounted() {
      this.rendered = true;  
    },
    methods: {
      handleChange() {
        // this.value = val;
        // console.log('hahahah', this.params.data);
        /* const { agUniqId } = this.params.data;
        const { colId } = this.params.column; */
        this.params.context.componentParent.changeSwitchVal(this.params.colDef.field, this.params.node, this.value);
        setTimeout(() => {
          /* await me.$API.financeSubject.account.put(reqData)
          delete row.$switch_isAccount */
          // 假装接口调用失败
          this.value = this.value === 1 ? 0 : 1;
          // this.params.context.componentParent.$refs.agTable.setRowData(this.params.data);
          console.log('还原啊？', this.value);
          this.params.context.componentParent.changeSwitchVal(this.params.colDef.field, this.params.node, this.value)
        }, 1000)
        /* if (this.rendered) {
          this.emitter.emit('changeSwitch', this.params.data);
        } else {
          console.log('渲染触发哦');
        } */
      }
    }
  };
  </script>
  
  <style></style>
  